<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>学习强国积分计算系统</title>
  </head>
  <body>
    <h1>学习强国积分计算系统</h1>
    <label>请输入7个数字(用逗号隔开)：</label>
    <input type="text" id="numbers"/><br/>
  
    <button onclick="calculate()">计算</button><br/><br/>
    
    <table>
      <tr>
        <th>总和：</th>
        <td id="sum"></td>
      </tr>
      <tr>
        <th>平均分：</th>
        <td id="average"></td>
      </tr>
    </table>
  
    <script>
      function calculate() {
        const numbers = document.getElementById("numbers").value.split(",");
        if (numbers.length !== 7) {
          alert("请输入7个数字！");
          return;
        }
        
        let sum = 0;
        for (let i = 0; i < numbers.length; i++) {
          const num = parseFloat(numbers[i]);
          if (isNaN(num)) {
            alert("请输入数字！");
            return;
          }
          sum += num;
        }
    
        const average = sum / 7;
        
        document.getElementById("sum").innerHTML = sum.toFixed(2); //保留两位小数
        document.getElementById("average").innerHTML = average.toFixed(2);
        
        //保存到本地数据库 
        localStorage.setItem("sum", sum);
        localStorage.setItem("average", average);
      }
    </script>
  </body>
</html>
